<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="20">

        <el-col :span="6" :xs="24">
          <user-card :user="user" />
        </el-col>

        <el-col :span="18" :xs="24">
          <el-tabs v-model="activeTab" type="border-card">
            <el-tab-pane label="基本资料" name="user-info">
              <user-info :rule-form="user" />
            </el-tab-pane>

            <el-tab-pane label="修改密码" name="edit-password">
              <edit-password />
            </el-tab-pane>
          </el-tabs>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UserCard from './components/UserCard'
import UserInfo from './components/UserInfo'
import EditPassword from './components/EditPassword'

export default {
  name: 'Profile',
  components: { UserCard, UserInfo, EditPassword },
  data() {
    return {
      user: {},
      activeTab: 'user-info'
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles'
    ])
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser() {
      this.user = {
        name: this.name,
        nickName: this.name + '_昵称',
        role: this.roles.join(' | '),
        mobile: '15618888888',
        email: 'admin@test.com',
        avatar: this.avatar,
        sex: 1
      }
    }
  }
}
</script>
